// SSE 工具，便于复用
export function createSSE(url: string, onMessage: (msg: string) => void, onError?: () => void) {
    const eventSource = new EventSource(url);
    eventSource.onmessage = (event) => {
      onMessage(event.data);
    };
    eventSource.onerror = () => {
      eventSource.close();
      onError && onError();
    };
    return eventSource;
  }